﻿using ZyGames.Framework.Game.Contract;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Tools;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 修改个人信息
	/// </summary>
	public class Action10061 : BaseAction
	{
		private int userId;
		private bool isMan;
		private string name;
		private string sign;
		private bool result = false;
		private string log = "";
		private int ChangeNickNameCost = 30;
		public Action10061(HttpGet actionGetter)
			: base((short)ActionType.DZEditSelfInfo, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("UserId", ref userId) &&
				httpGet.GetBool("IsMan", ref isMan) &&
				httpGet.GetString("Name", ref name) &&
				httpGet.GetString("Signature",ref sign))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			var currentGameUser = GameTable.Current.GetUser(userId);
			if (currentGameUser == null)
			{
				Tool.WriteWarmingLine("消息10061玩家不存在");
				result = false;
				return true;
			}
			currentGameUser.Sex = isMan;
			if(!string.Equals(currentGameUser.NickName, name))
			{
				if(!currentGameUser.HaveChangedNickName)
				{
					currentGameUser.HaveChangedNickName = true;
				}
				else
				{
					//要扣除相关的费用
					if (currentGameUser.GameCoin <= ChangeNickNameCost)
					{
						log = "金币不足，不能改名";
						result = false;
						return true;
					}
					else
					{
						currentGameUser.GameCoin -= ChangeNickNameCost;
					}
				}
				
			}
			currentGameUser.NickName = name;
			currentGameUser.Sign = sign;
			log = "改名成功";
			result = true;
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.result);
			this.PushIntoStack(this.log);
		}
	}
}
